package com.cndw.kungfu.model.goods.app;

import java.util.Map;

import com.cndw.kungfu.domain.Scene;
import com.cndw.kungfu.exception.ErrPopException;
import com.cndw.kungfu.ext.LanguageLib;
import com.cndw.kungfu.model.Context;

/**
 * 药品的使用
 * @author fantadust [9677889@qq.com]
 * @date 2011-9-13 下午2:59:57
 */
public class AppDo101 extends AppBase {

	@Override
	public boolean check() throws Exception {
		
		boolean isUse = false;
		if (goodsMode.getValueA() > 0 && player.getHp() < player.getMaxHp() ) {
			isUse = true;
		}
		if (goodsMode.getValueB() > 0 && player.getMp() < player.getMaxMp() ) {
			isUse = true;
		}	
		if (isUse == false) {			
			throw new ErrPopException(LanguageLib.get("goods.use.full"));			
		}
		Scene scene = Context.getSceneServer().getSceneById(player.getSceneId());
		if (scene != null && scene.isCityUnionWar()) {
			throw new ErrPopException(LanguageLib.get("goods.use.seige"));	
		}
		
		return true;
	}


	@Override
	public Map<String, Object> run() throws Exception {			

		
		player.alterHp(goodsMode.getValueA());
		player.alterMp(goodsMode.getValueB());
		player.commitSync();
		
		msg.put("hp", player.getHp());
		msg.put("mp", player.getMp());
		
		ticpString = LanguageLib.get("goods.use.suc");
		
		return msg;
	}



	
}
